package com.learn.demo.service;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 延迟队列接收
 *
 * @author banjiawei
 * @date 2021/11/23
 */
@Component
@Slf4j
public class MessageReceiver {
    //RabbitMQConfig配置的延迟队列名称
    @RabbitListener(queues = "MQ.LazyQueue")
    @RabbitHandler
    public void onLazyMessage(Message msg, Channel channel) throws IOException {
        long deliveryTag = msg.getMessageProperties().getDeliveryTag();
        log.info("deliveryTag {}", deliveryTag);
        log.info("lazy receive {}", new String(msg.getBody()));
    }
}
